import wx
class App(wx.App):
    def OnInit(self):
        self.frame = Frame()
        self.SetTopWindow(self.frame)
        self.frame.Show(True)
        self.frame = WaitFrame()
        self.frame.Show(False)
        self.frame = Finish()
        self.frame.Show(False)
        return True
class Frame(wx.Frame):
    checkdict={'减法表闪卡   ：': False, '加法表闪卡   ：': False, '乘法表闪卡   ：': False,
               '自定义闪卡': False, '三字经识字闪卡': False, '英文字母闪卡': False,
               '除法表闪卡   ：': False, 'slight words 闪卡': False, '数字闪卡      ：': False,
               '圆点识数闪卡：':False}
    fontlist = ['微软雅黑','宋体','楷体','隶书','方正小篆体','Bell MT','Bradley Hand ITC','Monotype Corsiva','Arial','Berlin Sans FB']
    blodlist = ['苗条点挺好','我要粗的']
    colorlist = ['黑底随机色字', '黑底粉字','黑底绿字', '黑底黄字','黑底白字','白底随机色字','白底绿字', '白底蓝字', '白底黑字']
    zidingyilist = ['单字、单词模式','短语、句子模式']
    dotlist = ['有大有小有趣的圆点','大小相同的传统圆点']
    colorchoise = 0
    fontname = 0
    blodchoise = 1
    zidingyichoise = 0
    dotchoise = 0

    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'PPT 闪卡生成器',size=(775, 530))
        #建立带滚轮的画布
        self.scroll = wx.ScrolledWindow(self, -1)
        self.scroll.SetVirtualSize((700, 530))
        self.scroll.SetScrollRate(1, 10)#滚动速度
        #添加欢迎文本
        welcome = wx.StaticText(self.scroll, -1,
'''
~~~欢迎使用“闪卡生成器” 选择要生成的闪卡内容后，设置幻灯片样式后按“生成闪卡”按钮即可~~~'
''',
                                (0, 0),(755,-1), wx.ALIGN_CENTER)
        welcome.SetForegroundColour('white')
        welcome.SetBackgroundColour('black')

        a=70
        b=30
        x=0
        get1=210+x
        get2=370+x
        word1=150+x
        word2=word1+160
        word3=word1+125
        self.letter_card = wx.CheckBox(self.scroll, -1, '英文字母闪卡', (35, a), (115, 20))
        self.slightwords_card = wx.CheckBox(self.scroll, -1, 'slight words 闪卡', (180, a), (115, 20))

        # 自定义闪卡
        self.words_card = wx.CheckBox(self.scroll, -1, '自定义闪卡', (470, a), (115, 20))
        prompt = wx.StaticText(self.scroll, -1, 'PPT分页模式:', (470, a + 20 ))
        self.zidingyichoise= wx.ComboBox(self.scroll, -1, '单字、单词模式',
                                       (550, a + 20), (160, 30), Frame.zidingyilist, wx.CB_DROPDOWN)
        basicLabel = wx.StaticText(self.scroll, -1, '请输入生成PPT的内容:', pos=(470, a + 50))
        # 添加可多行输入的自定义输入框
        self.get_text = wx.TextCtrl(self.scroll, -1,
'''中英文都可以
自动过滤标点符号、空格等
内容粘贴过来的同时记得在上方↑“自定义闪卡”处打钩
选择好喜欢的幻灯片样式后就可以点击下方生成PPT闪卡按钮生成PPT了''',
                               size=(240, 140), pos=(470, a + 70),style=wx.TE_MULTILINE)
        a+=b
        wx.StaticText(self.scroll, -1, '请输入自定义PPT的文件名:', pos=(470, a + 190))
        self.get_filename = wx.TextCtrl(self.scroll, -1, '', size=(240, -1), pos=(470, a + 210))

        self.sanzijin_card = wx.CheckBox(self.scroll, -1, '三字经识字闪卡', (35, a), (115, 20))
        a += b

        self.dot_card = wx.CheckBox(self.scroll, -1, '圆点识数闪卡：', (35, a), (115, 20))
        wx.StaticText(self.scroll, -1, '起始数字:', pos=(word1, a))
        self.get_dot_start = wx.TextCtrl(self.scroll, -1, '1', size=(50, -1), pos=(get1, a))
        wx.StaticText(self.scroll, -1, '至', pos=(word3, a))
        wx.StaticText(self.scroll, -1, '终止数字:', pos=(word2, a))
        self.get_dot_end = wx.TextCtrl(self.scroll, -1, '100', size=(50, -1), pos=(get2, a))
        a += b
        wx.StaticText(self.scroll, -1, '圆点样式', pos=(word1, a))
        self.dotchoise = wx.ComboBox(self.scroll, -1, '有大有小有趣的圆点',
                                       (210, a), (210, 30), Frame.dotlist, wx.CB_DROPDOWN)
        a = a + b

        self.munber_card = wx.CheckBox(self.scroll, -1, '数字闪卡      ：', (35, a), (115, 20))
        wx.StaticText(self.scroll, -1, '起始数字:', pos=(word1, a))
        self.get_munber_start = wx.TextCtrl(self.scroll, -1, '1',size=(50, -1), pos=(get1, a))
        wx.StaticText(self.scroll, -1, '至', pos=(word3, a))
        wx.StaticText(self.scroll, -1, '终止数字:', pos=(word2, a))
        self.get_munber_end = wx.TextCtrl(self.scroll, -1,'10', size=(50, -1), pos=(get2, a))
        a += b

        self.add_table_card = wx.CheckBox(self.scroll, -1, '加法表闪卡   ：', (35, a), (115, 20))
        wx.StaticText(self.scroll, -1, '起始数字:', pos=(word1, a))
        self.get_addtable_start = wx.TextCtrl(self.scroll, -1, '1',size=(50, -1), pos=(get1, a))
        wx.StaticText(self.scroll, -1, '至', pos=(word3, a))
        wx.StaticText(self.scroll, -1, '终止数字:', pos=(word2, a))
        self.get_addtable_end = wx.TextCtrl(self.scroll, -1, '10',size=(50, -1), pos=(get2, a))
        a += b

        self.sub_table_card = wx.CheckBox(self.scroll, -1, '减法表闪卡   ：', (35, a), (115, 20))
        wx.StaticText(self.scroll, -1, '起始数字:', pos=(word1, a))
        self.get_subtable_start = wx.TextCtrl(self.scroll, -1,'1', size=(50, -1), pos=(get1, a))
        wx.StaticText(self.scroll, -1, '至', pos=(word3, a))
        wx.StaticText(self.scroll, -1, '终止数字:', pos=(word2, a))
        self.get_subtable_end = wx.TextCtrl(self.scroll, -1, '10',size=(50, -1), pos=(get2, a))
        a += b

        self.mul_table_card = wx.CheckBox(self.scroll, -1, '乘法表闪卡   ：', (35, a), (115, 20))
        wx.StaticText(self.scroll, -1, '起始数字:', pos=(word1, a))
        self.get_multable_start = wx.TextCtrl(self.scroll, -1, '1',size=(50, -1), pos=(get1, a))
        wx.StaticText(self.scroll, -1, '至', pos=(word3, a))
        wx.StaticText(self.scroll, -1, '终止数字:', pos=(word2, a))
        self.get_multable_end = wx.TextCtrl(self.scroll, -1,'10', size=(50, -1), pos=(get2, a))
        a += b

        self.div_table_card = wx.CheckBox(self.scroll, -1, '除法表闪卡   ：', (35, a), (115, 20))
        wx.StaticText(self.scroll, -1, '起始数字:', pos=(word1, a))
        self.get_divtable_start = wx.TextCtrl(self.scroll, -1,'1', size=(50, -1), pos=(get1, a))
        wx.StaticText(self.scroll, -1, '至', pos=(word3, a))
        wx.StaticText(self.scroll, -1, '终止数字:', pos=(word2, a))
        self.get_divtable_end = wx.TextCtrl(self.scroll, -1, '10',size=(50, -1), pos=(get2, a))


        wx.StaticText(self.scroll, -1, '请设置幻灯片样式：', pos=(35, a+40))
        c=35
        d=239
        wx.StaticText(self.scroll, -1, '请选择PPT字体:', (c, a+70))
        self.fontchoise=wx.ComboBox(self.scroll, -1, '微软雅黑',
                                    (c+95,a+70), (100,30),Frame.fontlist,wx.CB_DROPDOWN)
        c+=d
        prompt = wx.StaticText(self.scroll, -1, '请选择字体加粗:', (c, a + 70))
        self.blodchoise = wx.ComboBox(self.scroll, -1, '我要粗的',
                                      (c + 95, a + 70), (100, 30), Frame.blodlist, wx.CB_DROPDOWN)
        c += d
        prompt = wx.StaticText(self.scroll, -1, '请选择配色方案:', (c, a + 70))
        self.colorchoise = wx.ComboBox(self.scroll, -1, '黑底随机色字',
                                       (c + 95, a + 70), (100, 30),Frame.colorlist, wx.CB_DROPDOWN)

        #添加按钮
        self.button = wx.Button(self.scroll, -1, '''！！！点这里生成PPT闪卡！！！
''', size=(675, -1), pos=(35, a + 105))
        wx.StaticText(self.scroll, -1, '一个字一张PPT，三字经这种1000多张PPT的电脑不够快要稍等一两分钟才行',
                             (0, a + 155), (760, -1), wx.ALIGN_CENTER)

        wx.StaticText(self.scroll, -1,'__________________________-o-小爷也是有底线的-o-__________________________',
                        (0, a + 200), (760, -1), wx.ALIGN_CENTER)

        self.Bind(wx.EVT_CHECKBOX, self.onChecked)#绑定CheckBox事件
        self.Bind(wx.EVT_BUTTON, self.CreatPPT, self.button)#绑定生成PPT按钮事件
    def onChecked(self, e):
        CheckBox = e.GetEventObject()
        Frame.checkdict[CheckBox.GetLabel()]=CheckBox.GetValue()
    def choise(self):
        colorchoise_cod = self.colorchoise.GetSelection()
        fontname_cod = self.fontchoise.GetSelection()
        blodchoise_cod = self.blodchoise.GetSelection()
        zidingyichoise_cod =self.zidingyichoise.GetSelection()
        dotchoise_cod =self.dotchoise.GetSelection()

        if colorchoise_cod != -1:
            Frame.colorchoise = colorchoise_cod
        if fontname_cod != -1:
            Frame.fontname = fontname_cod
        if blodchoise_cod != -1:
            Frame.blodchoise = blodchoise_cod
        if zidingyichoise_cod !=-1:
            Frame.zidingyichoise =zidingyichoise_cod
        if dotchoise_cod != -1:
            Frame.dotchoise = dotchoise_cod
    def check(self):
        Frame.choise(self)
        contentstr = self.get_text.GetValue()
        filename = self.get_filename.GetValue()
        dot_start = self.get_dot_start.GetValue()
        dot_end = self.get_dot_end.GetValue()
        munber_start = self.get_munber_start.GetValue()
        munber_end = self.get_munber_end.GetValue()
        addtable_start = self.get_addtable_start.GetValue()
        addtable_end = self.get_addtable_end.GetValue()
        subtable_start = self.get_subtable_start.GetValue()
        subtable_end = self.get_subtable_end.GetValue()
        multable_start = self.get_multable_start.GetValue()
        multable_end = self.get_multable_end.GetValue()
        divtable_start = self.get_divtable_start.GetValue()
        divtable_end = self.get_divtable_end.GetValue()

        errorlist = []
        def errorcheck(start,end,name):
            errorlist=[]
            try:
                if int(start) >= int(end):
                    x = name + '起始数字要比终止数字小才行哈！~~~⊙﹏⊙'
                    errorlist.append(x)
            except:
                x = name + '起始和终止值只能填整数哈，负整数也行，其他的都不行~~~(▔﹏▔)'
                errorlist.append(x)
            return errorlist
        if Frame.checkdict['自定义闪卡'] == True:
            if filename == '':
                x = '生成自定义闪卡需要输入文件名才行呦~~>o<'
                errorlist.append(x)
            if contentstr =='':
                x = '自定义闪卡的内容您还没输入呢~~+﹏+'
                errorlist.append(x)
        if Frame.checkdict['圆点识数闪卡：'] == True:
            if (dot_start.encode( 'UTF-8' ).isdigit() is False) or(dot_end.encode( 'UTF-8' ).isdigit() is False):
                x = '圆点闪卡只支持正整数~~˙︿˙'
                errorlist.append(x)
            else:
                if int(dot_start) < 0 or int(dot_end) < 0:
                    x = '圆点闪卡只支持正整数~~~⊙﹏⊙'
                    errorlist.append(x)
                if int(dot_end) > 200:
                    x = '圆点闪卡终止值最大只支持200点~~~(▔﹏▔)'
                    errorlist.append(x)
                if int(dot_start) >= int(dot_end):
                    x = '圆点闪卡起始数字要比终止数字小才行哈！~~~＋﹏＋'
                    errorlist.append(x)
        if Frame.checkdict['数字闪卡      ：'] == True:
            errorlist = errorlist + errorcheck(munber_start, munber_end, '数字闪卡')
        if Frame.checkdict['加法表闪卡   ：'] == True:
            errorlist = errorlist + errorcheck(addtable_start, addtable_end, '加法表闪卡')
        if Frame.checkdict['减法表闪卡   ：'] == True:
            errorlist = errorlist + errorcheck(subtable_start, subtable_end, '减法表闪卡')
        if Frame.checkdict['乘法表闪卡   ：'] == True:
            errorlist = errorlist + errorcheck(multable_start, multable_end, '乘法表闪卡')
        if Frame.checkdict['除法表闪卡   ：'] == True:
            errorlist = errorlist + errorcheck(divtable_start, divtable_end, '除法表闪卡')

        errorcontent = ''
        if len(errorlist) > 0:
            for i in range(len(errorlist)):
                errorcontent = errorcontent + '\n' + errorlist[i]
        errorcontent = errorcontent + '\n'

        if len(errorlist) > 2:
            errorcontent = errorcontent + '___________________________________________________________\n\n￣□￣｜｜  能出这么多问题，你是在玩我呢吧~~惹急了我咬你哈！' + '\n'
        if len(errorlist) > 0:
            dlg = wx.MessageDialog(None,errorcontent,'出错了，出错了~~', wx.ICON_QUESTION)
            result = dlg.ShowModal()
            dlg.Destroy()
        return len(errorlist)
    def pptmaker(self):
        Frame.choise(self)
        contentstr = self.get_text.GetValue()
        filename = self.get_filename.GetValue()
        dot_start = self.get_dot_start.GetValue()
        dot_end = self.get_dot_end.GetValue()
        munber_start = self.get_munber_start.GetValue()
        munber_end = self.get_munber_end.GetValue()
        addtable_start = self.get_addtable_start.GetValue()
        addtable_end = self.get_addtable_end.GetValue()
        subtable_start = self.get_subtable_start.GetValue()
        subtable_end = self.get_subtable_end.GetValue()
        multable_start = self.get_multable_start.GetValue()
        multable_end = self.get_multable_end.GetValue()
        divtable_start = self.get_divtable_start.GetValue()
        divtable_end = self.get_divtable_end.GetValue()

        a = PPTMaker()
        filenamelist = []
        if Frame.checkdict['slight words 闪卡'] == True:
            filename = a.PPT_slightwords(Frame.colorchoise, Frame.fontname, Frame.blodchoise)
            filenamelist = filenamelist + filename
        if Frame.checkdict['三字经识字闪卡'] == True:
            filename = a.PPT_sanzijing(Frame.colorchoise, Frame.fontname, Frame.blodchoise)
            filenamelist = filenamelist + filename
        if Frame.checkdict['英文字母闪卡'] == True:
            filename = a.PPT_letter(Frame.colorchoise, Frame.fontname, Frame.blodchoise)
            filenamelist = filenamelist + filename
        if Frame.checkdict['自定义闪卡'] == True:
            if Frame.zidingyichoise == 0:
                contentlist = a.listmaker(contentstr)
            else:
                contentlist = a.listmaker2(contentstr)
            name = a.filename(filename, Frame.colorchoise, Frame.blodchoise,Frame.fontname)
            filename = a.PPT_maker(contentlist, Frame.colorchoise, Frame.fontname, Frame.blodchoise, name)
            filenamelist = filenamelist + filename
        if Frame.checkdict['圆点识数闪卡：'] == True:
            filename = Dotcard.Creat(self, dot_start, dot_end, Frame.colorchoise, Frame.dotchoise)
            filenamelist = filenamelist + filename
        if Frame.checkdict['数字闪卡      ：'] == True:
            filename = a.PPT_munber(munber_start, munber_end, Frame.colorchoise, Frame.fontname, Frame.blodchoise)
            filenamelist = filenamelist + filename
        if Frame.checkdict['加法表闪卡   ：'] == True:
            filename = a.PPT_addtable(addtable_start, addtable_end, Frame.colorchoise, Frame.fontname, Frame.blodchoise)
            filenamelist = filenamelist + filename
        if Frame.checkdict['减法表闪卡   ：'] == True:
            filename = a.PPT_subtable(subtable_start, subtable_end, Frame.colorchoise, Frame.fontname, Frame.blodchoise)
            filenamelist = filenamelist + filename
        if Frame.checkdict['乘法表闪卡   ：'] == True:
            filename = a.PPT_multable(multable_start, multable_end, Frame.colorchoise, Frame.fontname, Frame.blodchoise)
            filenamelist = filenamelist + filename
        if Frame.checkdict['除法表闪卡   ：'] == True:
            filename = a.PPT_divtable(divtable_start, divtable_end, Frame.colorchoise, Frame.fontname, Frame.blodchoise)
            filenamelist = filenamelist + filename
        return filenamelist
    def move(self,filenamelist):
        import os
        import shutil

        path1 = os.getcwd()  # 获取当前执行文件的路径
        path2 = path1 + '\我的闪卡'  # 执行路径中的闪卡文件夹
        path3 = os.path.join(os.path.expanduser("~"), 'Desktop')  # 尝试获取桌面路径
        path4 = path3 + '\我的闪卡'  # 桌面上的闪卡文件夹
        if os.path.exists(path3):  # 如果能找到桌面的位置
            path = path4
            if os.path.exists(path4):
                pass
            else:
                os.makedirs(path4)
            for i in range(len(filenamelist)):  # 将生成的PPT转移到新的文件夹
                if os.path.exists(path1 + '\\' + filenamelist[i]):
                    shutil.move(path1 + '\\' + filenamelist[i], path4 + '\\' + filenamelist[i])
                else:
                    print('未找到：%s' % filenamelist[i])
        else:
            path = path2
            if os.path.exists(path2):
                pass  # 检查文件夹中是否有该文件夹，有的话过
            else:
                os.makedirs(path2)  # 没有的话建立文件夹
            for i in range(len(filenamelist)):  # 将生成的PPT转移到新的文件夹
                if os.path.exists(path1 + '\\' + filenamelist[i]):
                    shutil.move(path1 + '\\' + filenamelist[i], path2 + '\\' + filenamelist[i])
                else: print('未找到：%s' % filenamelist[i])
        return path
    def CreatPPT(self,a):
        import time
        import sys
        Frame.choise(self)
        if True not in Frame.checkdict.values():
            dlg = wx.MessageDialog(None,'还没勾选要生成的闪卡呢~~让我给你生个猴儿~~啊 >_<',
                                   '出错了，出错了~~', wx.ICON_QUESTION)
            result = dlg.ShowModal()
            dlg.Destroy()
        else:
            do = Frame.check(self) #检查错误
            if do == 0:
                #生成中提示
                a = wx.Window.GetPosition(self)
                WaitFrame.x = a[0]+200
                WaitFrame.y = a[1]+230
                waitframe = WaitFrame()
                waitframe.Show(True)

                time_start = time.time()
                filenamelist = Frame.pptmaker(self) #生成PPT
                path = Frame.move(self, filenamelist) #转移ppt至闪卡文件夹

                time_end = time.time()
                waitframe.Destroy()

                Finish.x = a[0] + 200
                Finish.y = a[1] + 100
                spend = time_end - time_start
                #spend = '%.2f'%spend
                Finish.spend = spend
                Finish.list = filenamelist
                Finish.path = path
                finish = Finish()
                finish.Show(True)
            else:pass
class PPTMaker():
    # 选择字体：输入体体字典的key，输出字体名称str
    def fontchoise(self,key):
        fontdict = {
            0: '微软雅黑', 5: 'Bell MT',
            1: '宋体', 6: 'Bradley Hand ITC',
            2: '楷体', 7: 'Monotype Corsiva',
            3: '隶书', 8: 'Arial',
            4: '方正小篆体', 9: 'Berlin Sans FB'
        }
        fontname = fontdict.get(key)
        return fontname
    # 选择幻灯片配色方案代号，输出6位list，前三位为背景色，后三位为字体颜色
    def colorchoise(self,cod):
        '''
        配色方案代号:
        0、黑底随机色字   1、黑底粉字  2、黑底绿字  3、黑底黄字
        4、黑底白字   5、白底随机色字   6、白底绿字  7、白底蓝字
        8、白底黑字
        '''
        import random
        colordict = {
            'snow': [255, 250, 250], 'grey21': [54, 54, 54],
            'yellow2': [238, 238, 0], 'SlateBlue': [106, 90, 205],
            'DarkOliveGreen1': [202, 255, 112], 'OliveDrab3': [154, 205, 50],
            'DarkViolet': [148, 0, 211], 'HotPink': [255, 105, 180],
            'bright':[random.randint(155, 250),random.randint(155, 250),random.randint(170, 250)],
            'dark':[random.randint(50, 150),random.randint(50, 150),random.randint(50, 150)]
         }
        colormodle = {
            0: colordict.get('grey21') + colordict.get('bright'),
            1: colordict.get('grey21') + colordict.get('HotPink'),
            2: colordict.get('grey21') + colordict.get('DarkOliveGreen1'),
            3: colordict.get('grey21') + colordict.get('yellow2'),
            4: colordict.get('grey21') + colordict.get('snow'),
            5: colordict.get('snow') + colordict.get('dark'),
            6: colordict.get('snow') + colordict.get('OliveDrab3'),
            7: colordict.get('snow') + colordict.get('SlateBlue'),
            8: colordict.get('snow') + colordict.get('grey21')
        }
        choise = colormodle.get(cod)
        return choise
    # 设置字号
    def fontsize(self,contentlist,i):
        from pptx.util import Inches, Pt
        if contentlist[i][0] >= u'\u4e00' and contentlist[i][0] <= u'\u9fa5':
            if len(contentlist[i]) == 1:fontsize = Pt(200)
            elif len(contentlist[i]) == 2:fontsize = Pt(160)
            elif len(contentlist[i]) == 3:fontsize = Pt(130)
            elif len(contentlist[i]) == 4:fontsize = Pt(110)
            elif 5 <= len(contentlist[i]) <= 10:fontsize = Pt(500 / len(contentlist[i]))
            else:fontsize = Pt(50)
        elif contentlist[i][0].encode('UTF-8').isalpha() or contentlist[i][0].encode('UTF-8').isdigit() \
            or contentlist[i][0] == "'" :
            if len(contentlist[i]) == 1:fontsize = Pt(200)
            elif len(contentlist[i]) == 2:fontsize = Pt(170)
            elif len(contentlist[i]) == 3 :fontsize = Pt(145)
            elif 4 <= len(contentlist[i]) < 7  :fontsize = Pt(125)
            elif 7 <= len(contentlist[i]) <= 10 : fontsize = Pt(850/len(contentlist[i]))
            elif 5 <= len(contentlist[i]) <= 15:fontsize = Pt(890 / len(contentlist[i]))
            else: Pt(58)
        else:fontsize = Pt(50)
        return fontsize

    #根据列表生成自定义闪卡,
    def PPT_maker(self,contentlist, colorchoise, fontname, blodcod, filename):
        '''
        contentlist: 用于生成PPT的列表，每张PPT1个列表元素
        colorchoise: 长度为6的列表，前三个数为背景颜色的RGB色值，后三个数为字体颜色的RGB数值
        fontname:字体名称的字符串
        blodcod:0或1，控制字体加粗，0为不加粗，1为加粗
        filename: PPT文件名，需带有后缀.pptx
        return: 生成ppt用时，同时生成ppt
        '''
        from pptx import Presentation
        from pptx.enum.shapes import MSO_AUTO_SHAPE_TYPE
        from pptx.util import Inches, Pt
        from pptx.dml.color import RGBColor

        prs = Presentation()  # 创建PPT
        wordmumber = len(contentlist)
        fontname = PPTMaker.fontchoise(self,fontname)

        for i in range(wordmumber):
            slide = prs.slides.add_slide(prs.slide_layouts[6])  # 新建空白页
            # 插入透方形
            shapes = slide.shapes
            left = Inches(0.0)
            top = Inches(0.0)
            width = Inches(10.0)
            height = Inches(7.5)
            shape = shapes.add_shape(
                MSO_AUTO_SHAPE_TYPE.RECTANGLE, left, top, width, height
            )
            # 设置背景颜色
            color = Dotcard.color(Dotcard, colorchoise)
            fill = shape.fill
            fill.solid()
            fill.fore_color.rgb = RGBColor(color[0], color[1], color[2])

            line = shape.line
            line.fill.background()

            # 添加文本
            text_frame = shape.text_frame
            p = text_frame.paragraphs[0]
            run = p.add_run()
            run.text = contentlist[i]

            # 设置文本样式
            font = run.font
            font.name = fontname  # 设置字体

            # 设置字号
            font.size = PPTMaker.fontsize(self,contentlist,i)

            # 设置加粗
            if blodcod ==0:
                font.bold = False
            else:
                font.bold = True
            font.italic = None  # cause value to be inherited from theme
            # 设置字体颜色
            font.color.rgb = RGBColor(color[3], color[4], color[5])

        adv.adv(self,prs,0,'微软雅黑',1)

        prs.save(filename)
        list=[filename]
        return list
    # 制作字母PPT闪卡
    def PPT_letter(self,colorchoise, fontname, blodcod,):
        contentlist = PPTMaker.letter(self)
        filename = PPTMaker.filename(self,'字母闪卡', colorchoise, blodcod,fontname)
        PPTMaker.PPT_maker(self,contentlist, colorchoise, fontname, blodcod, filename)
        list = [filename]
        return list
    # 制作数字闪卡
    def PPT_munber(self,start, end, colorchoise, fontname, blodcod):
        contentlist = PPTMaker.munber(self, start, end)
        filename = PPTMaker.filename(self, str(start) + '-' + str(end) + '数字闪卡', colorchoise, blodcod,fontname)
        PPTMaker.PPT_maker(self,contentlist, colorchoise, fontname, blodcod, filename)
        list = [filename]
        return list
    # 制作加法表闪卡
    def PPT_addtable(self, range1, range2,colorchoise, fontname, blodcod):
        contentlist1 = PPTMaker.table(self,"add", range1, range2, "whole")
        contentlist2 = PPTMaker.table(self,"add", range1, range2, "half")
        filename1 = PPTMaker.filename(self, str(range1) + '-' + str(range2) + '加法表（whole）', colorchoise, blodcod,
                                      fontname)
        filename2 = PPTMaker.filename(self, str(range1) + '-' + str(range2) + '加法表（half）', colorchoise, blodcod,
                                      fontname)
        PPTMaker.PPT_maker(self,contentlist1, colorchoise, fontname, blodcod, filename1)
        PPTMaker.PPT_maker(self,contentlist2, colorchoise, fontname, blodcod, filename2)
        list=[filename1,filename2]
        return list
    # 制作减法表闪卡
    def PPT_subtable(self, range1, range2,colorchoise, fontname, blodcod):
        contentlist1 = PPTMaker.table(self,"sub", range1, range2, "whole")
        contentlist2 = PPTMaker.table(self,"sub", range1, range2, "half")
        filename1 = PPTMaker.filename(self, str(range1) + '-' + str(range2) + '减法表（whole）', colorchoise, blodcod,
                                      fontname)
        filename2 = PPTMaker.filename(self, str(range1) + '-' + str(range2) + '减法表（half）', colorchoise, blodcod,
                                      fontname)
        PPTMaker.PPT_maker(self,contentlist1, colorchoise, fontname, blodcod, filename1)
        PPTMaker.PPT_maker(self,contentlist2, colorchoise, fontname, blodcod, filename2)
        list = [filename1, filename2]
        return list
    # 制作乘法表闪卡
    def PPT_multable(self, range1, range2,colorchoise, fontname, blodcod):
        contentlist1 = PPTMaker.table(self,"mul", range1, range2, "whole")
        contentlist2 = PPTMaker.table(self,"mul", range1, range2, "half")
        filename1 = PPTMaker.filename(self, str(range1) + '-' + str(range2) + '乘法表（whole）', colorchoise, blodcod,
                                      fontname)
        filename2 = PPTMaker.filename(self, str(range1) + '-' + str(range2) + '乘法表（half）', colorchoise, blodcod,
                                      fontname)
        PPTMaker.PPT_maker(self,contentlist1, colorchoise, fontname, blodcod, filename1)
        PPTMaker.PPT_maker(self,contentlist2, colorchoise, fontname, blodcod, filename2)
        list = [filename1, filename2]
        return list
    # 制作除法表闪卡
    def PPT_divtable(self, range1, range2,colorchoise, fontname, blodcod):
        contentlist1 = PPTMaker.table(self,"div", range1, range2, "whole")
        contentlist2 = PPTMaker.table(self,"div", range1, range2, "half")
        filename1 = PPTMaker.filename(self, str(range1) + '-' + str(range2) + '除法表（whole）', colorchoise, blodcod, fontname)
        filename2 = PPTMaker.filename(self, str(range1) + '-' + str(range2) + '除法表（half）', colorchoise, blodcod, fontname)
        PPTMaker.PPT_maker(self,contentlist1, colorchoise, fontname, blodcod, filename1)
        PPTMaker.PPT_maker(self,contentlist2, colorchoise, fontname, blodcod, filename2)
        list = [filename1, filename2]
        return list
    # 制作三字经闪卡
    def PPT_sanzijing(self,colorchoise, fontname, blodcod):
        contentstr='''
        人之初，性本善。性相近，习相远。苟不教，性乃迁。教之道，贵以专。昔孟母，择邻处。子不学，断机杼。
        窦燕山，有义方。教五子，名俱扬。养不教，父之过。教不严，师之惰。子不学，非所宜。幼不学，老何为。
        玉不琢，不成器。人不学，不知义。为人子，方少时。亲师友，习礼仪。香九龄，能温席。孝于亲，所当执。
        融四岁，能让梨。弟于长，宜先知。首孝悌，次见闻。知某数，识某文。一而十，十而百。百而千，千而万。
        三才者，天地人。三光者，日月星。三纲者，君臣义。父子亲，夫妇顺。曰春夏，曰秋冬。此四时，运不穷。
        曰南北，曰西东。此四方，应乎中。曰水火，木金土。此五行，本乎数。十干者，甲至癸。十二支，子至亥。
        曰黄道，日所躔。曰赤道，当中权。赤道下，温暖极。我中华，在东北。曰江河，曰淮济。此四渎，水之纪。
        曰岱华，嵩恒衡。此五岳，山之名。曰士农，曰工商。此四民，国之良。曰仁义，礼智信。此五常，不容紊。
        地所生，有草木。此植物，遍水陆。有虫鱼，有鸟兽。此动物，能飞走。稻粱菽，麦黍稷。此六谷，人所食。
        马牛羊，鸡犬豕。此六畜，人所饲。曰喜怒，曰哀惧。爱恶欲，七情具。青赤黄，及黑白。此五色，目所识。
        酸苦甘，及辛咸。此五味，口所含。膻焦香，及腥朽。此五臭，鼻所嗅。匏土革，木石金。丝与竹，乃八音。
        曰平上，曰去入。此四声，宜调协。高曾祖，父而身。身而子，子而孙。自子孙，至玄曾。乃九族，人之伦。
        父子恩，夫妇从。兄则友，弟则恭。长幼序，友与朋。君则敬，臣则忠。此十义，人所同。当师叙，勿违背。
        斩齐衰，大小功。至缌麻，五服终。礼乐射，御书数。古六艺，今不具。惟书学，人共遵。既识字，讲说文。
        有古文，大小篆。隶草继，不可乱。若广学，惧其繁。但略说，能知原。凡训蒙，须讲究。详训诂，明句读。
        为学者，必有初。小学终，至四书。论语者，二十篇。群弟子，记善言。孟子者，七篇止。讲道德，说仁义。
        作中庸，子思笔。中不偏，庸不易。作大学，乃曾子。自修齐，至平治。孝经通，四书熟。如六经，始可读。
        诗书易，礼春秋。号六经，当讲求。有连山，有归藏。有周易，三易详。有典谟，有训诰。有誓命，书之奥。
        我周公，作周礼。著六官，存治体。大小戴，注礼记。述圣言，礼乐备。曰国风，曰雅颂。号四诗，当讽咏。
        诗既亡，春秋作。寓褒贬，别善恶。三传者，有公羊。有左氏，有谷梁。经既明，方读子。撮其要，记其事。
        五子者，有荀扬。文中子，及老庄。经子通，读诸史。考世系，知始终。自羲农，至黄帝。号三皇，居上世。
        唐有虞，号二帝。相揖逊，称盛世。夏有禹，商有汤。周武王，称三王。夏传子，家天下。四百载，迁夏社。
        汤伐夏，国号商。六百载，至纣亡。周武王，始诛纣。八百载，最长久。周辙东，王纲坠。逞干戈，尚游说。
        始春秋，终战国。五霸强，七雄出。嬴秦氏，始兼并。传二世，楚汉争。高祖兴，汉业建。至孝平，王莽篡。
        光武兴，为东汉。四百年，终于献。魏蜀吴，争汉鼎。号三国，迄两晋。宋齐继，梁陈承。为南朝，都金陵。
        北元魏，分东西。宇文周，与高齐。迨至隋，一土宇。不再传，失统绪。唐高祖，起义师。除隋乱，创国基。
        二十传，三百载。梁灭之，国乃改。梁唐晋，及汉周。称五代，皆有由。炎宋兴，受周禅。十八传，南北混。
        辽与金，皆称帝。元灭金，绝宋世。舆图广，超前代。九十年，国祚废。太祖兴，国大明。号洪武，都金陵。
        迨成祖，迁燕京。十六世，至崇祯。权阉肆，寇如林。李闯出，神器焚。清世祖，膺景命。靖四方，克大定。
        由康雍，历乾嘉。民安富，治绩夸。道咸间，变乱起。始英法，扰都鄙。同光后，宣统弱。传九帝，满清殁。
        革命兴，废帝制。立宪法，建民国。古今史，全在兹。载治乱，知兴衰。史虽繁，读有次。史记一，汉书二。
        后汉三，国志四。兼证经，参通鉴。读史者，考实录。通古今，若亲目。昔仲尼，师项橐。古圣贤，尚勤学。
        赵中令，读鲁论。彼既仕，学且勤。披蒲编，削竹简。彼无书，且知勉。头悬梁，锥刺股。彼不教，自勤苦。
        如囊萤，如映雪。家虽贫，学不辍。如负薪，如挂角。身虽劳，犹苦卓。苏老泉，二十七。始发愤，读书籍。
        彼既老，犹悔迟。尔小生，宜早思。若梁灏，八十二。对大廷，魁多士。彼既成，众称异。尔小生，宜立志。
        莹八岁，能咏诗。泌七岁，能赋棋。彼颖悟，人称奇。尔幼学，当效之。蔡文姬，能辩琴。谢道韫，能咏吟。
        彼女子，且聪敏。尔男子，当自警。唐刘晏，方七岁。举神童，作正字。口而诵，心而惟。朝于斯，夕于斯。
        晏虽幼，身已仕。有为者，亦若是。犬守夜，鸡司晨。苟不学，曷为人。蚕吐丝，蜂酿蜜。人不学，不如物。
        幼而学，壮而行。上致君，下泽民。扬名声，显父母。光于前，裕于后。人遗子，金满赢。我教子，唯一经。
        勤有功，戏无益。戒之哉，宜勉力。
        '''
        contentlist = PPTMaker.listmaker(self,contentstr)
        filename = PPTMaker.filename(self, '三字经闪卡', colorchoise, blodcod, fontname)
        PPTMaker.PPT_maker(self,contentlist, colorchoise, fontname, blodcod, filename)
        list = [filename]
        return list
    # 制作slight words 闪卡
    def PPT_slightwords(self,colorchoise, fontname, blodcod):
        Pre_primer = 'a  and  away  big  blue  can  come  down  find  for  funny  go  help  here  I  in is  it  jump  little  look  make  me  my  not  one  play  red  run  said  see the  three  to  two  up  we  where  yellow  you'
        Primer = 'all  am  are  at  ate  be  black brown  but  came  did  do  eat  four  get  good have  he  into  like  must  new  no  now  on  our  out  please  pretty  ran  ride saw  say  she  so  soon  that  there  they  this  too  under  want  was  well went  what  white  who  will  with  yes'
        GradeOne = 'after  again  an  any  ask  as  by  could  every  fly  from  give  going  had  has her  him  his  how  just  know  let  live  may  of  old  once  open  over  put round  some  stop  take  thank  them  then  think  walk  were  when'
        Gradetwo = 'always  around  because  been  before  best  both  buy  call  cold  does  don’t fast  first  five  found  gave  goes  green  its  made  many  off  or  pull  read right  sing  sit  sleep  tell  their  these  those  upon  us  use  very  wash which  why  wish  work  would  write your'
        Gradethree = 'about  better  bring  carry  clean  cut  done  draw  drink  eight  fall  far  full got  grow  hold  hot  hurt  if  keep  kind  laugh  light  long  much  myself  never only  own  pick  seven  shall  show  six  small  start  ten  today  together  try warm'

        Pre_primer_list = PPTMaker.listmaker(self,Pre_primer)
        Primer_list = PPTMaker.listmaker(self,Primer)
        GradeOne_list = PPTMaker.listmaker(self,GradeOne)
        Gradetwo_list = PPTMaker.listmaker(self,Gradetwo)
        Gradethree_list = PPTMaker.listmaker(self,Gradethree)

        filename_Pre=PPTMaker.filename(self,'slightwords_Pre_primer',colorchoise,blodcod,fontname)
        filename_Primer=PPTMaker.filename(self,'slightwords_Primer',colorchoise,blodcod,fontname)
        filename_1=PPTMaker.filename(self,'slightwords_GradeOne',colorchoise,blodcod,fontname)
        filename_2=PPTMaker.filename(self,'slightwords_Gradetwo',colorchoise,blodcod,fontname)
        filename_3=PPTMaker.filename(self,'slightwords_Gradethree',colorchoise,blodcod,fontname)

        PPTMaker.PPT_maker(self,Pre_primer_list, colorchoise, fontname, blodcod, filename_Pre)
        PPTMaker.PPT_maker(self,Primer_list, colorchoise, fontname, blodcod, filename_Primer)
        PPTMaker.PPT_maker(self,GradeOne_list, colorchoise, fontname, blodcod, filename_1)
        PPTMaker.PPT_maker(self,Gradetwo_list, colorchoise, fontname, blodcod, filename_2)
        PPTMaker.PPT_maker(self,Gradethree_list, colorchoise, fontname, blodcod, filename_3)
        list = [filename_Pre,filename_Primer,filename_1,filename_2,filename_3]
        return list
    # 生成加减乘除法表的list，add输出加法表，sub为减法表，为mul输出乘法表，div为除法表8
    def table(self,arithmetic, range1, range2, integrity):
        '''
        arithmentic为add输出加法表，sub为减法表，为mul输出乘法表，div为除法表
        range1,range2为范围
        integrity为whole输出完整表格，为half输出一半的表格
        '''
        range1=int(range1)
        range2=int(range2)
        range2 = range2 + 1
        range3 = range1
        range4 = range2
        list = []
        for a in range(range1, range2):
            for b in range(range3, range4):
                cell = ''
                if arithmetic == 'add':
                    c = a + b
                    cell = str(a) + '+' + str(b) + '=' + str(c)
                if arithmetic == 'sub':
                    c = a + b
                    cell = str(c) + '-' + str(a) + '=' + str(b)
                if arithmetic == 'mul':
                    c = a * b
                    cell = str(a) + '×' + str(b) + '=' + str(c)
                if arithmetic == 'div':
                    c = a * b
                    cell = str(c) + '÷' + str(a) + '=' + str(b)
                list.append(cell)
            if integrity == 'half':
                range3 = range3 + 1
        return list
    # 输入起始与终止数值生成等差递增数列list
    def munber(self,start,end):
        list = []
        for a in range(int(start), int(end) + 1):
            list.append(str(a))
        return list
    # 生成26个字母表list，分别为大写、小写、大小写和在一起
    def letter(self):
        lowercase = [chr(i) for i in range(97, 123)]
        capitals = [chr(i) for i in range(65, 91)]
        combine = [chr(i) for i in range(97, 123)]
        for i in range(len(lowercase)):
            combine[i] = capitals[i] + ' ' + lowercase[i]
        letter_list = lowercase
        letter_list.extend(capitals)
        letter_list.extend(combine)
        return letter_list
    # 将字符串加工成list，适用于中文\英文\数字（需用空格隔开）
    def listmaker(self,content):
        contentlist = []
        a = 0
        while a < len(content):
            contentcleaner = ''
            if content[a] >= u'\u4e00' and content[a] <= u'\u9fa5':
                contentcleaner = content[a]
                contentlist.append(contentcleaner)
                a += 1
            elif (content[a].encode('UTF-8').isalpha()) or content[a] == "'" or \
                (content[a].encode('UTF-8').isdigit()):
                content = content + ' '
                while ((content[a].encode('UTF-8').isalpha()) or content[a] == "'" or \
                       (content[a].encode('UTF-8').isdigit())) \
                    and (a < len(content)):
                    contentcleaner = contentcleaner + content[a]
                    a += 1
                contentlist.append(contentcleaner)
            else:
                a += 1
        return contentlist
    # 用于短语等，以回车为判断标准进行分割
    def listmaker2(self,content):
        contentlist = []
        a = 0
        content = content + '\n'
        while a < len(content):
            contentcleaner = ''
            if content[a] == '\n':
                a += 1
            else:
                while content[a] != '\n' and a < len(content):
                    contentcleaner = contentcleaner + content[a]
                    a += 1
                contentlist.append(contentcleaner)
        return contentlist
    # 将.生成文件名
    def filename(self,name,colorchoise,blodcod,fontname):
        filename_head = str(name)
        col = str(Frame.colorlist[int(colorchoise)])
        font = str(Frame.fontlist[int(fontname)])
        blod =''
        if int(blodcod) == 0:
            blod = ''
        if int(blodcod) == 1:
            blod = '加粗'
        filename = filename_head + '_' + col + '_' + font +  '_' + blod + '.pptx'
        return filename
class Dotcard():
    # 圆点大小与距离设置
    ##########################################################3
    randome = 0  # size==0时为随机直径圆点的
    fixed = 1  # size==1时为固定直径圆点
    a = 0.4  # 最大直径，1个圆点的大小，单位inch
    b = 0.1  # 最小点的直径
    c = 150  # 最小点的起始数量，这个数量之后点不再减小
    dis = 1.8  # 点与点之间的最小距离系数
    spacerate = 1.2  # 分配每个点所需的最小空间，1.5是基数
    d_min = 0.6  # 圆点大小各异的情况下最小直径系数
    d_max = 1.6  # 圆点大小各异的情况下最大直径系数 ,不得大于dis

    # 最大绘制区域设置
    ###########################################################
    d = 1.5  # 最大区域的left起点
    e = 10 - d  # 最大区域的left终点
    g = 0.75  # 高与宽的比值
    o = 10  # ppt的总宽度

    # 指数圆点绘制区域设置 y = s + t * (p ** count)
    ###########################################################
    s = 0.05  # 将指数函数向上平移
    t = 2  # 将曲线在y轴上拉长或压扁
    p = 0.2  # 取值（0<p<1）,前几个点想增大的快点就调大

    # 根据点的数量生成圆点的直径(0为恒定直径，1为大小不一的直径)
    def diameter(self, dotquantity, size):  # 设置圆点直径
        import random
        if size == Dotcard.fixed:
            if 0 < dotquantity <= Dotcard.c:
                diameter = Dotcard.a - (dotquantity - 1) * (Dotcard.a - Dotcard.b) / (Dotcard.c - 1)
            if Dotcard.c < dotquantity:
                diameter = Dotcard.b
        if size == Dotcard.randome:
            if dotquantity == 1:
                diameter = Dotcard.a - (dotquantity - 1) * (Dotcard.a - Dotcard.b) / (Dotcard.c - 1)
            if 1 < dotquantity <= Dotcard.c:
                diameter = Dotcard.a - (dotquantity - 1) * (Dotcard.a - Dotcard.b) / (Dotcard.c - 1)
                diameter = diameter * random.uniform(Dotcard.d_min, Dotcard.d_max)
            if Dotcard.c < dotquantity:
                diameter = Dotcard.b * random.uniform(Dotcard.d_min, Dotcard.d_max)

        return diameter
    # 根据圆点的数量随机生成点的坐标（在randompose中调用）
    def randompose(self, dotquantity, size):
        import random
        import math
        m = Dotcard.diameter(self, dotquantity, Dotcard.fixed)  # 绘制点的直径
        dis = Dotcard.dis
        pos = []

        ############### 绘制区域的最大值 #############
        c = Dotcard.d  # 最大left左边坐标
        d = Dotcard.e  # 最大left右边坐标

        ################## 指数型增长下绘制区域的最小值 ################
        j = Dotcard.p  # 指数函数 y = j ** x的常熟

        ### 判断点所占空间 ###
        space = ((Dotcard.spacerate * dis * m) ** 2) * dotquantity
        long = math.sqrt(space / Dotcard.g)  # 单点做占用空间的x轴长度

        ### 基础坐标区间 ###
        baseleft1 = (Dotcard.o / 2) - m * dis - m / 2
        baseleft2 = (Dotcard.o / 2) + m * dis - m / 2
        basehight1 = baseleft1 * Dotcard.g - m / 2
        basehight2 = baseleft2 * Dotcard.g - m / 2

        ### 第二个以后点的坐标区间 ###
        left1 = baseleft1 - (Dotcard.s + Dotcard.t * (j ** dotquantity)) * dotquantity
        left2 = baseleft2 + (Dotcard.s + Dotcard.t * (j ** dotquantity)) * dotquantity
        top1 = basehight1 - (Dotcard.s + Dotcard.t * (j ** dotquantity)) * Dotcard.g * dotquantity
        top2 = basehight2 + (Dotcard.s + Dotcard.t * (j ** dotquantity)) * Dotcard.g * dotquantity

        ### 所需space比绘制区域大时的坐标区间 ###
        lf1 = Dotcard.o / 2 - long / 2 - m / 2
        lf2 = Dotcard.o / 2 + long / 2 - m / 2
        to1 = Dotcard.g * (Dotcard.o / 2 - long / 2) - m / 2
        to2 = Dotcard.g * (Dotcard.o / 2 + long / 2) - m / 2

        ##############################################################
        if dotquantity == 1:
            left = Dotcard.o / 2 - m / 2
            top = left * Dotcard.g
            siz = Dotcard.diameter(self, dotquantity, Dotcard.fixed)
            pos = [left, top, siz]

        if dotquantity > 1:
            if space < (d - c) * (d - c) * Dotcard.g:  # 如果绘画空间小于最大空间
                if (left2 - left1) * (top2 - top1) < (d - c) * (d - c) * Dotcard.g:  # 如果绘画区域小于最大区域
                    if space <= (left2 - left1) * (top2 - top1):  # 如果绘画空间比线性和或指数的空间小
                        left = random.uniform(left1, left2)
                        top = random.uniform(top1, top2)
                        siz = Dotcard.diameter(self, dotquantity, size)
                        pos = [left, top, siz]
                    else:
                        left = random.uniform(lf1, lf2)
                        top = random.uniform(to1, to2)
                        siz = Dotcard.diameter(self, dotquantity, size)
                        pos = [left, top, siz]
                else:
                    left = random.uniform(c, d)
                    top = random.uniform(c * Dotcard.g, d * Dotcard.g)
                    siz = Dotcard.diameter(self, dotquantity, size)
                    pos = [left, top, siz]
            else:
                print('点数为 %d 的闪卡可能画不出来了' % dotquantity)
        return pos
    # 生成一定数量的，具有一定距离的点的坐标列表（在create中调用）
    def poslist(self, dotquantity, size):
        import math
        count = 0
        poslist = []  # 记录每个点的位置
        while count < dotquantity:
            count = count + 1
            d = Dotcard.diameter(self, dotquantity, Dotcard.fixed)
            if len(poslist) > 0:
                list = [0]
                a = []
                while 0 in list:
                    list = []
                    for m in range(len(poslist)): list.append(0)  # 生成与点数位数相同位数的列表
                    pos = Dotcard.randompose(self, dotquantity, size)
                    x = pos[0]
                    y = pos[1]
                    for n in range(len(poslist)):
                        dis = math.sqrt((x - poslist[n][0]) ** 2 + (y - poslist[n][1]) ** 2)
                        if dis > d * Dotcard.dis:
                            list[n] = 1
                            a = pos
                poslist.append(a)
            if len(poslist) == 0:  # 第一个点直接添加到列表中
                pos = Dotcard.randompose(self, dotquantity, size)
                poslist.append(pos)
        return poslist
    def color(self, colorchoise):
        color = PPTMaker.colorchoise(self, colorchoise)
        return color
    # 生成圆点闪卡的函数，size为0为固定直径的点，为1是随机直径的点
    def anyshape(end):
        import random
        return random.randint(0, end)
    def Creat(self, range1, range2, colorchoise, size):
        from pptx import Presentation
        from pptx.enum.shapes import MSO_AUTO_SHAPE_TYPE
        from pptx.util import Inches, Pt
        from pptx.dml.color import RGBColor
        import time

        time_start = time.time()
        shapelist = [MSO_AUTO_SHAPE_TYPE.OVAL, MSO_AUTO_SHAPE_TYPE.RECTANGLE, MSO_AUTO_SHAPE_TYPE.ISOSCELES_TRIANGLE,
                     MSO_AUTO_SHAPE_TYPE.STAR_4_POINT,MSO_AUTO_SHAPE_TYPE.STAR_5_POINT, MSO_AUTO_SHAPE_TYPE.EXPLOSION1]
        namelist =[]
        for shapestyle in range(len(shapelist)+1):
            prs = Presentation()  # 创建PPT
            color = Dotcard.color(self, colorchoise)
            for i in range(int(range1), int(range2) + 1):
                slide = prs.slides.add_slide(prs.slide_layouts[6])  # 新建空白页
                # 插入方形
                shapes = slide.shapes
                left = Inches(0.0)
                top = Inches(0.0)
                width = Inches(10.0)
                height = Inches(7.5)
                shape = shapes.add_shape(MSO_AUTO_SHAPE_TYPE.RECTANGLE, left, top, width, height)
                # 设置背景颜色
                fill = shape.fill
                fill.solid()
                fill.fore_color.rgb = RGBColor(color[0], color[1], color[2])
                # 设置边框
                line = shape.line
                line.fill.background()

                ################## 插入数字页码 ####################
                # 插入方形
                shapes = slide.shapes
                left = Inches(9.4)
                top = Inches(7.2)
                width = Inches(0.6)
                height = Inches(0.3)
                shape = shapes.add_shape(MSO_AUTO_SHAPE_TYPE.RECTANGLE, left, top, width, height)
                # 设置背景颜色
                fill = shape.fill
                fill.solid()
                fill.fore_color.rgb = RGBColor(color[0], color[1], color[2])
                # 设置边框
                line = shape.line
                line.fill.background()
                # 添加文本
                text_frame = shape.text_frame
                p = text_frame.paragraphs[0]
                run = p.add_run()
                run.text = str(i)
                # 设置文本样式
                font = run.font
                font.name = "微软雅黑"  # 设置字体
                # 设置字号、加粗与倾斜
                font.size = Pt(14)
                font.bold = False
                font.italic = None
                # 设置字体颜色
                font.color.rgb = RGBColor(color[3], color[4], color[5])

                ################# 插入圆点 ######################
                dotlist = Dotcard.poslist(self, i, size)  # 生成圆点列表
                for i in range(len(dotlist)):
                    shape2 = slide.shapes
                    left = Inches(dotlist[i][0])
                    top = Inches(dotlist[i][1])
                    width = Inches(dotlist[i][2])
                    height = Inches(dotlist[i][2])
                    anyshape = shapelist[Dotcard.anyshape(len(shapelist)-1)]
                    shapelist2 = shapelist + [anyshape]
                    addshape = shape2.add_shape(shapelist2[shapestyle], left, top, width, height)

                    # 设置背景颜色
                    color = Dotcard.color(self, colorchoise)
                    fill = addshape.fill
                    fill.solid()
                    fill.fore_color.rgb = RGBColor(color[3], color[4], color[5])
                    line = addshape.line
                    line.fill.background()

            adv.adv(self, prs, 0, '微软雅黑', 1)
            col = Frame.colorlist[int(colorchoise)]

            shapelist3 = shapelist + [0]
            shapedict = {MSO_AUTO_SHAPE_TYPE.OVAL: '圆形', MSO_AUTO_SHAPE_TYPE.RECTANGLE: '正方形', MSO_AUTO_SHAPE_TYPE.ISOSCELES_TRIANGLE: '三角形',
                         MSO_AUTO_SHAPE_TYPE.STAR_4_POINT: '四角星', MSO_AUTO_SHAPE_TYPE.STAR_5_POINT: '五角星', MSO_AUTO_SHAPE_TYPE.EXPLOSION1: '爆炸型',
                         0: '随机形状'}
            shapename = shapedict.get(shapelist3[shapestyle])
            if size == Dotcard.fixed:
                filename = str(range1) + '至' + str(range2) + shapename + '圆点闪卡（固定直径' + col + '）.pptx'
            else:
                filename = str(range1) + '至' + str(range2) + shapename + '圆点闪卡（随机直径' + col + '）.pptx'
            prs.save(filename)
            namelist.append(filename)
        return namelist
class WaitFrame(Frame):
    x=0
    y=0
    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'PPT闪卡正在生成中，请稍侯~~~~~~~~~~~~~', size=(350, 10),pos=(WaitFrame.x,WaitFrame.y),style=wx.CAPTION)
        panel = wx.Panel(self)
class Finish(Frame):
    x = 0
    y = 0
    list = []
    path = ''
    spend= 0.00
    def __init__(self):
        sizeh = 220 + len(self.list) * 17
        wx.Frame.__init__(self, None, -1, '闪卡都做好喽~~~', size=(430, sizeh), pos=(Finish.x, Finish.y))
        panel = wx.Panel(self)
        button = wx.Button(panel, label='~~点这儿查看闪卡~~', pos=(140, 20))
        self.Bind(wx.EVT_BUTTON, self.open, button)
        word2 = wx.StaticText(panel, -1, Finish.words(self),(30, 60))

    def words(self):
        filenamelist = Finish.list
        word = '只用了%f秒哦~~\n保存至：%s'%(self.spend,self.path)
        word = word + "\n_______________________________________________________________________\n\n生成文件：\n"
        for i in range(len(filenamelist)):
            word = word + "      " + filenamelist[i] + '\n'
        return word

    def open(self,event):
        import os
        os.startfile(self.path)
        self.Close(True)
class adv():
    def adv(self,prs,colorchoise,fontname,blodcod):
        slide = adv.back(self, prs, colorchoise)  #设置背景颜色
        adv.star(self, slide, 5) #画星星

        # 插入文本框1
        left = 1.0
        top = 2.6
        width = 8.0
        height = 1.0
        content = 'THE END'
        fontsize = 85
        text1 = adv.text(self,slide,colorchoise,left,top,width,height,content,fontname,fontsize,blodcod)

        # 插入文本框2
        left = 1.0
        top = 3.4
        width = 8.0
        height = 1.0
        content = '欢乐是成长的养分，兴趣是教育的根本'
        fontsize = 21
        text2 = adv.text(self, slide, colorchoise, left, top, width, height, content, fontname, fontsize,blodcod)

        #插入文本框3
        left = 1.0
        top = 4.2
        width = 8.0
        height = 1.0
        content = '爱伴双语幼儿会馆   ICan Kindergarten'
        fontsize = 16
        text3 = adv.text(self, slide, colorchoise, left, top, width, height, content, fontname, fontsize, blodcod)

        # 插入文本框4
        left = 1.0
        top = 4.5
        width = 8.0
        height = 1.0
        content = '地址：北京市朝阳区梵谷水局17好楼103     联系人：clara     Tel/WeChat：13581912711'
        fontsize = 12
        text3 = adv.text(self, slide, colorchoise, left, top, width, height, content, fontname, fontsize, blodcod)
    def back(self,prs,colorchoise):
        from pptx.enum.shapes import MSO_AUTO_SHAPE_TYPE
        from pptx.util import Inches, Pt
        from pptx.dml.color import RGBColor

        slide = prs.slides.add_slide(prs.slide_layouts[6])  # 新建空白页
        # 插入透方形
        shapes = slide.shapes
        left = Inches(0.0)
        top = Inches(0.0)
        width = Inches(10.0)
        height = Inches(7.5)
        shape = shapes.add_shape(MSO_AUTO_SHAPE_TYPE.RECTANGLE, left, top, width, height)
        # 设置背景颜色
        color = Dotcard.color(Dotcard, colorchoise)
        fill = shape.fill
        fill.solid()
        fill.fore_color.rgb = RGBColor(color[0], color[1], color[2])
        line = shape.line
        line.fill.background()
        return slide
    def star(self,slide,colorchoise):
        from pptx.enum.shapes import MSO_AUTO_SHAPE_TYPE
        from pptx.util import Inches, Pt
        from pptx.dml.color import RGBColor
        import math
        import random

        count = 0
        poslist = []  # 记录每个点的位置
        while count < 99:
                count = count + 1
                d = Dotcard.diameter(self, 99, Dotcard.fixed)
                if len(poslist) > 0:
                    list = [0]
                    a = []
                    while 0 in list:
                        list = []
                        for m in range(len(poslist)): list.append(0)  # 生成与点数位数相同位数的列表
                        pos = Dotcard.randompose(self, 99, 1)
                        x = random.uniform(0,10)
                        y = random.uniform(0,7)
                        size = Dotcard.diameter(self,99,0)
                        pos=[x,y,size]
                        for n in range(len(poslist)):
                            dis = math.sqrt((x - poslist[n][0]) ** 2 + (y - poslist[n][1]) ** 2)
                            if dis > d * Dotcard.dis:
                                list[n] = 1
                                a = pos
                    poslist.append(a)
                if len(poslist) == 0:  # 第一个点直接添加到列表中
                    pos = Dotcard.randompose(self, 99, 1)
                    poslist.append(pos)

        for i in range(len(poslist)):
                shape2 = slide.shapes
                left = Inches(poslist[i][0])
                top = Inches(poslist[i][1])
                width = Inches(poslist[i][2])
                height = Inches(poslist[i][2])
                shape_oval = shape2.add_shape(MSO_AUTO_SHAPE_TYPE.STAR_4_POINT, left, top, width, height)

                # 设置背景颜色
                color = Dotcard.color(self, colorchoise)
                fill = shape_oval.fill
                fill.solid()
                fill.fore_color.rgb = RGBColor(color[3], color[4], color[5])
                line = shape_oval.line
                line.fill.background()
    def text(self,slide,colorchoise,left,top,width,height,content,fontname,fontsize,blodcod):
        from pptx.enum.shapes import MSO_AUTO_SHAPE_TYPE
        from pptx.util import Inches, Pt
        from pptx.dml.color import RGBColor

        shapes = slide.shapes
        left = Inches(left)
        top = Inches(top)
        width = Inches(width)
        height = Inches(height)
        shape = shapes.add_shape(MSO_AUTO_SHAPE_TYPE.RECTANGLE, left, top, width, height)
        shape.fill.background()
        line = shape.line
        line.fill.background()

        # 添加文本
        text_frame = shape.text_frame
        p = text_frame.paragraphs[0]
        run = p.add_run()
        run.text = content

        # 设置文本样式
        font = run.font
        font.name = fontname  # 设置字体

        # 设置字号
        font.size = Pt(fontsize)

        # 设置加粗
        if blodcod == 0:
            font.bold = False
        else:
            font.bold = True
        font.italic = None  # cause value to be inherited from theme
        # 设置字体颜色
        color = Dotcard.color(Dotcard, colorchoise)
        font.color.rgb = RGBColor(color[3], color[4], color[5])
if __name__ == '__main__':
    app = App()
    app.MainLoop()


